home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / u_man / cat1 / perlbot.Z / perlbot
Encoding:
Text File  |  1998-10-28  |  19.4 KB  |  793 lines

  1.  
  2.  
  3.  
  4.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       perlbot - Bag'o Object Tricks    (the BOT)
  10.  
  11.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.       The following    collection of tricks and hints is intended to
  13.       whet curious appetites about such things as the use of
  14.       instance variables and the mechanics of object and class
  15.       relationships.  The reader is    encouraged to consult relevant
  16.       textbooks for    discussion of Object Oriented definitions and
  17.       methodology.    This is    not intended as    a tutorial for
  18.       object-oriented programming or as a comprehensive guide to
  19.       Perl's object    oriented features, nor should it be construed
  20.       as a style guide.
  21.  
  22.       The Perl motto still holds:  There's more than one way to do
  23.       it.
  24.  
  25.      OOOOOOOO    SSSSCCCCAAAALLLLIIIINNNNGGGG    TTTTIIIIPPPPSSSS
  26.       1    Do not attempt to verify    the type of $self.  That'll
  27.            break if    the class is inherited,    when the type of $self
  28.            is valid    but its    package    isn't what you expect.    See
  29.            rule 5.
  30.  
  31.       2    If an object-oriented (OO) or indirect-object (IO)
  32.            syntax was used,    then the object    is probably the
  33.            correct type and    there's    no need    to become paranoid
  34.            about it.  Perl isn't a paranoid    language anyway.  If
  35.            people subvert the OO or    IO syntax then they probably
  36.            know what they're doing and you should let them do it.
  37.            See rule    1.
  38.  
  39.       3    Use the two-argument form of _b_l_e_s_s().  Let a subclass
  40.            use your    constructor.  See the section on _I_N_H_E_R_I_T_I_N_G _A
  41.            _C_O_N_S_T_R_U_C_T_O_R.
  42.  
  43.       4    The subclass is allowed to know things about its
  44.            immediate superclass, the superclass is allowed to know
  45.            nothing about a subclass.
  46.  
  47.       5    Don't be    trigger    happy with inheritance.     A "using",
  48.            "containing", or    "delegation" relationship (some    sort
  49.            of aggregation, at least) is often more appropriate.
  50.            See the section on _O_B_J_E_C_T _R_E_L_A_T_I_O_N_S_H_I_P_S,    the section on
  51.            _U_S_I_N_G _R_E_L_A_T_I_O_N_S_H_I_P _W_I_T_H _S_D_B_M, and the section on
  52.            _D_E_L_E_G_A_T_I_O_N.
  53.  
  54.       6    The object is the namespace.  Make package globals
  55.            accessible via the object.  This    will remove the    guess
  56.            work about the symbol's home package.  See the section
  57.            on _C_L_A_S_S    _C_O_N_T_E_X_T    _A_N_D _T_H_E    _O_B_J_E_C_T.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  71.  
  72.  
  73.  
  74.       7    IO syntax is certainly less noisy, but it is also prone
  75.            to ambiguities that can cause difficult-to-find bugs.
  76.            Allow people to use the sure-thing OO syntax, even if
  77.            you don't like it.
  78.  
  79.       8    Do not use function-call    syntax on a method.  You're
  80.            going to    be bitten someday.  Someone might move that
  81.            method into a superclass    and your code will be broken.
  82.            On top of that you're feeding the paranoia in rule 2.
  83.  
  84.       9    Don't assume you    know the home package of a method.
  85.            You're making it    difficult for someone to override that
  86.            method.    See the    section    on _T_H_I_N_K_I_N_G _O_F _C_O_D_E _R_E_U_S_E.
  87.  
  88.      IIIINNNNSSSSTTTTAAAANNNNCCCCEEEE VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS
  89.       An anonymous array or    anonymous hash can be used to hold
  90.       instance variables.  Named parameters    are also demonstrated.
  91.  
  92.           package Foo;
  93.  
  94.           sub new {
  95.               my $type = shift;
  96.               my %params = @_;
  97.               my $self = {};
  98.               $self->{'High'} = $params{'High'};
  99.               $self->{'Low'}  = $params{'Low'};
  100.               bless    $self, $type;
  101.           }
  102.  
  103.           package Bar;
  104.  
  105.           sub new {
  106.               my $type = shift;
  107.               my %params = @_;
  108.               my $self = [];
  109.               $self->[0] = $params{'Left'};
  110.               $self->[1] = $params{'Right'};
  111.               bless    $self, $type;
  112.           }
  113.  
  114.           package main;
  115.  
  116.           $a = Foo->new( 'High'    => 42, 'Low' =>    11 );
  117.           print    "High=$a->{'High'}\n";
  118.           print    "Low=$a->{'Low'}\n";
  119.  
  120.           $b = Bar->new( 'Left'    => 78, 'Right' => 40 );
  121.           print    "Left=$b->[0]\n";
  122.           print    "Right=$b->[1]\n";
  123.  
  124.  
  125.      SSSSCCCCAAAALLLLAAAARRRR IIIINNNNSSSSTTTTAAAANNNNCCCCEEEE VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS
  126.  
  127.  
  128.  
  129.      PPPPaaaaggggeeee 2222                        ((((pppprrrriiiinnnntttteeeedddd 11110000////22223333////99998888))))
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  137.  
  138.  
  139.  
  140.       An anonymous scalar can be used when only one    instance
  141.       variable is needed.
  142.  
  143.           package Foo;
  144.  
  145.           sub new {
  146.               my $type = shift;
  147.               my $self;
  148.               $self    = shift;
  149.               bless    \$self,    $type;
  150.           }
  151.  
  152.           package main;
  153.  
  154.           $a = Foo->new( 42 );
  155.           print    "a=$$a\n";
  156.  
  157.  
  158.      IIIINNNNSSSSTTTTAAAANNNNCCCCEEEE VVVVAAAARRRRIIIIAAAABBBBLLLLEEEE IIIINNNNHHHHEEEERRRRIIIITTTTAAAANNNNCCCCEEEE
  159.       This example demonstrates how    one might inherit instance
  160.       variables from a superclass for inclusion in the new class.
  161.       This requires    calling    the superclass's constructor and
  162.       adding one's own instance variables to the new object.
  163.  
  164.           package Bar;
  165.  
  166.           sub new {
  167.               my $type = shift;
  168.               my $self = {};
  169.               $self->{'buz'} = 42;
  170.               bless    $self, $type;
  171.           }
  172.  
  173.           package Foo;
  174.           @ISA = qw( Bar );
  175.  
  176.           sub new {
  177.               my $type = shift;
  178.               my $self = Bar->new;
  179.               $self->{'biz'} = 11;
  180.               bless    $self, $type;
  181.           }
  182.  
  183.           package main;
  184.  
  185.           $a = Foo->new;
  186.           print    "buz = ", $a->{'buz'}, "\n";
  187.           print    "biz = ", $a->{'biz'}, "\n";
  188.  
  189.  
  190.      OOOOBBBBJJJJEEEECCCCTTTT RRRREEEELLLLAAAATTTTIIIIOOOONNNNSSSSHHHHIIIIPPPPSSSS
  191.       The following    demonstrates how one might implement
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  203.  
  204.  
  205.  
  206.       "containing" and "using" relationships between objects.
  207.  
  208.           package Bar;
  209.  
  210.           sub new {
  211.               my $type = shift;
  212.               my $self = {};
  213.               $self->{'buz'} = 42;
  214.               bless    $self, $type;
  215.           }
  216.  
  217.           package Foo;
  218.  
  219.           sub new {
  220.               my $type = shift;
  221.               my $self = {};
  222.               $self->{'Bar'} = Bar->new;
  223.               $self->{'biz'} = 11;
  224.               bless    $self, $type;
  225.           }
  226.  
  227.           package main;
  228.  
  229.           $a = Foo->new;
  230.           print    "buz = ", $a->{'Bar'}->{'buz'},    "\n";
  231.           print    "biz = ", $a->{'biz'}, "\n";
  232.  
  233.  
  234.      OOOOVVVVEEEERRRRRRRRIIIIDDDDIIIINNNNGGGG    SSSSUUUUPPPPEEEERRRRCCCCLLLLAAAASSSSSSSS MMMMEEEETTTTHHHHOOOODDDDSSSS
  235.       The following    example    demonstrates how to override a
  236.       superclass method and    then call the overridden method.  The
  237.       SSSSUUUUPPPPEEEERRRR    pseudo-class allows the    programmer to call an
  238.       overridden superclass    method without actually    knowing    where
  239.       that method is defined.
  240.  
  241.           package Buz;
  242.           sub goo { print "here's the goo\n" }
  243.  
  244.           package Bar; @ISA = qw( Buz );
  245.           sub google { print "google here\n" }
  246.  
  247.           package Baz;
  248.           sub mumble { print "mumbling\n" }
  249.  
  250.           package Foo;
  251.           @ISA = qw( Bar Baz );
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 10/23/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  269.  
  270.  
  271.  
  272.           sub new {
  273.               my $type = shift;
  274.               bless    [], $type;
  275.           }
  276.           sub grr { print "grumble\n" }
  277.           sub goo {
  278.               my $self = shift;
  279.               $self->SUPER::goo();
  280.           }
  281.           sub mumble {
  282.               my $self = shift;
  283.               $self->SUPER::mumble();
  284.           }
  285.           sub google {
  286.               my $self = shift;
  287.               $self->SUPER::google();
  288.           }
  289.  
  290.           package main;
  291.  
  292.           $foo = Foo->new;
  293.           $foo->mumble;
  294.           $foo->grr;
  295.           $foo->goo;
  296.           $foo->google;
  297.  
  298.  
  299.      UUUUSSSSIIIINNNNGGGG RRRREEEELLLLAAAATTTTIIIIOOOONNNNSSSSHHHHIIIIPPPP    WWWWIIIITTTTHHHH SSSSDDDDBBBBMMMM
  300.       This example demonstrates an interface for the SDBM class.
  301.       This creates a "using" relationship between the SDBM class
  302.       and the new class Mydbm.
  303.  
  304.           package Mydbm;
  305.  
  306.           require SDBM_File;
  307.           require Tie::Hash;
  308.           @ISA = qw( Tie::Hash );
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.      Page 5                        (printed 10/23/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  335.  
  336.  
  337.  
  338.           sub TIEHASH {
  339.               my $type = shift;
  340.               my $ref  = SDBM_File->new(@_);
  341.               bless {'dbm' => $ref}, $type;
  342.           }
  343.           sub FETCH {
  344.               my $self = shift;
  345.               my $ref  = $self->{'dbm'};
  346.               $ref->FETCH(@_);
  347.           }
  348.           sub STORE {
  349.               my $self = shift;
  350.               if (defined $_[0]){
  351.               my $ref = $self->{'dbm'};
  352.               $ref->STORE(@_);
  353.               }    else {
  354.               die "Cannot STORE an undefined key in    Mydbm\n";
  355.               }
  356.           }
  357.  
  358.           package main;
  359.           use Fcntl qw(    O_RDWR O_CREAT );
  360.  
  361.           tie %foo, "Mydbm", "Sdbm", O_RDWR|O_CREAT, 0640;
  362.           $foo{'bar'} =    123;
  363.           print    "foo-bar = $foo{'bar'}\n";
  364.  
  365.           tie %bar, "Mydbm", "Sdbm2", O_RDWR|O_CREAT, 0640;
  366.           $bar{'Cathy'}    = 456;
  367.           print    "bar-Cathy = $bar{'Cathy'}\n";
  368.  
  369.  
  370.      TTTTHHHHIIIINNNNKKKKIIIINNNNGGGG OOOOFFFF CCCCOOOODDDDEEEE RRRREEEEUUUUSSSSEEEE
  371.       One strength of Object-Oriented languages is the ease    with
  372.       which    old code can use new code.  The    following examples
  373.       will demonstrate first how one can hinder code reuse and
  374.       then how one can promote code    reuse.
  375.  
  376.       This first example illustrates a class which uses a fully-
  377.       qualified method call    to access the "private"    method _B_A_Z().
  378.       The second example will show that it is impossible to
  379.       override the _B_A_Z() method.
  380.  
  381.           package FOO;
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.      Page 6                        (printed 10/23/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  401.  
  402.  
  403.  
  404.           sub new {
  405.               my $type = shift;
  406.               bless    {}, $type;
  407.           }
  408.           sub bar {
  409.               my $self = shift;
  410.               $self->FOO::private::BAZ;
  411.           }
  412.  
  413.           package FOO::private;
  414.  
  415.           sub BAZ {
  416.               print    "in BAZ\n";
  417.           }
  418.  
  419.           package main;
  420.  
  421.           $a = FOO->new;
  422.           $a->bar;
  423.  
  424.       Now we try to    override the _B_A_Z() method.  We would like
  425.       _F_O_O::_b_a_r() to    call _G_O_O_P::_B_A_Z(), but this cannot happen
  426.       because _F_O_O::_b_a_r() explicitly    calls _F_O_O::_p_r_i_v_a_t_e::_B_A_Z().
  427.  
  428.           package FOO;
  429.  
  430.           sub new {
  431.               my $type = shift;
  432.               bless    {}, $type;
  433.           }
  434.           sub bar {
  435.               my $self = shift;
  436.               $self->FOO::private::BAZ;
  437.           }
  438.  
  439.           package FOO::private;
  440.  
  441.           sub BAZ {
  442.               print    "in BAZ\n";
  443.           }
  444.  
  445.           package GOOP;
  446.           @ISA = qw( FOO );
  447.           sub new {
  448.               my $type = shift;
  449.               bless    {}, $type;
  450.           }
  451.  
  452.           sub BAZ {
  453.               print    "in GOOP::BAZ\n";
  454.           }
  455.  
  456.  
  457.  
  458.  
  459.      Page 7                        (printed 10/23/98)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  467.  
  468.  
  469.  
  470.           package main;
  471.  
  472.           $a = GOOP->new;
  473.           $a->bar;
  474.  
  475.       To create reusable code we must modify class FOO, flattening
  476.       class    FOO::private.  The next    example    shows a    reusable class
  477.       FOO which allows the method _G_O_O_P::_B_A_Z() to be    used in    place
  478.       of _F_O_O::_B_A_Z().
  479.  
  480.           package FOO;
  481.  
  482.           sub new {
  483.               my $type = shift;
  484.               bless    {}, $type;
  485.           }
  486.           sub bar {
  487.               my $self = shift;
  488.               $self->BAZ;
  489.           }
  490.  
  491.           sub BAZ {
  492.               print    "in BAZ\n";
  493.           }
  494.  
  495.           package GOOP;
  496.           @ISA = qw( FOO );
  497.  
  498.           sub new {
  499.               my $type = shift;
  500.               bless    {}, $type;
  501.           }
  502.           sub BAZ {
  503.               print    "in GOOP::BAZ\n";
  504.           }
  505.  
  506.           package main;
  507.  
  508.           $a = GOOP->new;
  509.           $a->bar;
  510.  
  511.  
  512.      CCCCLLLLAAAASSSSSSSS CCCCOOOONNNNTTTTEEEEXXXXTTTT AAAANNNNDDDD TTTTHHHHEEEE OOOOBBBBJJJJEEEECCCCTTTT
  513.       Use the object to solve package and class context problems.
  514.       Everything a method needs should be available    via the    object
  515.       or should be passed as a parameter to    the method.
  516.  
  517.       A class will sometimes have static or    global data to be used
  518.       by the methods.  A subclass may want to override that    data
  519.       and replace it with new data.     When this happens the
  520.       superclass may not know how to find the new copy of the
  521.       data.
  522.  
  523.  
  524.  
  525.      Page 8                        (printed 10/23/98)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  533.  
  534.  
  535.  
  536.       This problem can be solved by    using the object to define the
  537.       context of the method.  Let the method look in the object
  538.       for a    reference to the data.    The alternative    is to force
  539.       the method to    go hunting for the data    ("Is it    in my class,
  540.       or in    a subclass?  Which subclass?"),    and this can be
  541.       inconvenient and will    lead to    hackery.  It is    better just to
  542.       let the object tell the method where that data is located.
  543.  
  544.           package Bar;
  545.  
  546.           %fizzle = ( 'Password' => 'XYZZY' );
  547.  
  548.           sub new {
  549.               my $type = shift;
  550.               my $self = {};
  551.               $self->{'fizzle'} = \%fizzle;
  552.               bless    $self, $type;
  553.           }
  554.  
  555.           sub enter {
  556.               my $self = shift;
  557.  
  558.               # Don't try to guess if we should use    %Bar::fizzle
  559.               # or %Foo::fizzle.  The object already knows which
  560.               # we should use, so just ask it.
  561.               #
  562.               my $fizzle = $self->{'fizzle'};
  563.  
  564.               print    "The word is ",    $fizzle->{'Password'}, "\n";
  565.           }
  566.  
  567.           package Foo;
  568.           @ISA = qw( Bar );
  569.  
  570.           %fizzle = ( 'Password' => 'Rumple' );
  571.  
  572.           sub new {
  573.               my $type = shift;
  574.               my $self = Bar->new;
  575.               $self->{'fizzle'} = \%fizzle;
  576.               bless    $self, $type;
  577.           }
  578.  
  579.           package main;
  580.  
  581.           $a = Bar->new;
  582.           $b = Foo->new;
  583.           $a->enter;
  584.           $b->enter;
  585.  
  586.  
  587.      IIIINNNNHHHHEEEERRRRIIIITTTTIIIINNNNGGGG    AAAA CCCCOOOONNNNSSSSTTTTRRRRUUUUCCCCTTTTOOOORRRR
  588.  
  589.  
  590.  
  591.      PPPPaaaaggggeeee 9999                        ((((pppprrrriiiinnnntttteeeedddd 11110000////22223333////99998888))))
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  599.  
  600.  
  601.  
  602.       An inheritable constructor should use    the second form    of
  603.       _b_l_e_s_s() which    allows blessing    directly into a    specified
  604.       class.  Notice in this example that the object will be a BAR
  605.       not a    FOO, even though the constructor is in class FOO.
  606.  
  607.           package FOO;
  608.  
  609.           sub new {
  610.               my $type = shift;
  611.               my $self = {};
  612.               bless    $self, $type;
  613.           }
  614.  
  615.           sub baz {
  616.               print    "in FOO::baz()\n";
  617.           }
  618.  
  619.           package BAR;
  620.           @ISA = qw(FOO);
  621.  
  622.           sub baz {
  623.               print    "in BAR::baz()\n";
  624.           }
  625.  
  626.           package main;
  627.  
  628.           $a = BAR->new;
  629.           $a->baz;
  630.  
  631.  
  632.      DDDDEEEELLLLEEEEGGGGAAAATTTTIIIIOOOONNNN
  633.       Some classes,    such as    SDBM_File, cannot be effectively
  634.       subclassed because they create foreign objects.  Such    a
  635.       class    can be extended    with some sort of aggregation
  636.       technique such as the    "using"    relationship mentioned earlier
  637.       or by    delegation.
  638.  
  639.       The following    example    demonstrates delegation    using an
  640.       _A_U_T_O_L_O_A_D() function to perform message-forwarding.  This
  641.       will allow the Mydbm object to behave    exactly    like an
  642.       SDBM_File object.  The Mydbm class could now extend the
  643.       behavior by adding custom _F_E_T_C_H() and    _S_T_O_R_E()    methods, if
  644.       this is desired.
  645.  
  646.           package Mydbm;
  647.  
  648.           require SDBM_File;
  649.           require Tie::Hash;
  650.           @ISA = qw(Tie::Hash);
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.      Page 10                        (printed 10/23/98)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  665.  
  666.  
  667.  
  668.           sub TIEHASH {
  669.               my $type = shift;
  670.               my $ref = SDBM_File->new(@_);
  671.               bless    {'delegate' => $ref};
  672.           }
  673.  
  674.           sub AUTOLOAD {
  675.               my $self = shift;
  676.  
  677.               # The    Perl interpreter places    the name of the
  678.               # message in a variable called $AUTOLOAD.
  679.  
  680.               # DESTROY messages should never be propagated.
  681.               return if $AUTOLOAD =~ /::DESTROY$/;
  682.  
  683.               # Remove the package name.
  684.               $AUTOLOAD =~ s/^Mydbm:://;
  685.  
  686.               # Pass the message to    the delegate.
  687.               $self->{'delegate'}->$AUTOLOAD(@_);
  688.           }
  689.  
  690.           package main;
  691.           use Fcntl qw(    O_RDWR O_CREAT );
  692.  
  693.           tie %foo, "Mydbm", "adbm", O_RDWR|O_CREAT, 0640;
  694.           $foo{'bar'} =    123;
  695.           print    "foo-bar = $foo{'bar'}\n";
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.      Page 11                        (printed 10/23/98)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLBBBBOOOOTTTT((((1111))))
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.      Page 12                        (printed 10/23/98)
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.